/*****************************************************************
**                                                             	**
**  Copyright (C) 2004 Amlogic,Inc.                            	**
**  All rights reserved                                        	**
**        Filename : WinWarnMessageBox.c /Project:AVOS		       **
**        Revision : 1.0                                       	**
**                                                             	**
*****************************************************************/
#include "../menu.h"
#include "WinWarnMessageBoxEvent.h"

INT32S WinWarnMessageBoxMsgProc(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_KEYDOWN:
            return WinWarnMessageBoxOnKeyPress(hwnd, lpParam) ;
        case WM_SHOWWINDOW:
            return WinWarnMessageBoxOnShow(hwnd, lpParam) ;  
        case WM_PAINT:
            return WinWarnMessageBoxOnPaint(hwnd, lpParam) ;          

    }
    return 0 ;
}

INT32S WarningBoxMsgProc(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return WarningBoxOnShow(hwnd, lpParam) ;
        case WM_KEYDOWN:
            return WarningBoxOnKeyPress(hwnd, lpParam) ;
        case WM_PAINT:
            return WarningBoxOnPaint(hwnd, lpParam) ;    
    }
    return 0 ;
}

void SetWinWarnMessageBoxPalette(void)
{
     YUVENTRY mask_para[4] = {0,79,4095,4095};
    AWSetAlphaMask(0,4, mask_para);
    YUVENTRY palette_para[16] = {0x8000 | 16392,0x8000 | 17832,0x8000 | 17204,0x8000 | 16392,18034,17972,17894,17863,18424,18424,20240,19000,13082,9146,23195,7196};
    AWSetPalette(0,16, palette_para);
    return ;
}

void SetWinWarnMessageBoxPos(HWND* pControl, INT8U CurOsdSize)
{
   
            RECT NormalWindowRect = {0,0,800,480};
            pControl->winrect = NormalWindowRect;
            CREATEWINDOWPARAM NormalWindowPara = {1,{{0,0,800,480},    {0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},    SetWinWarnMessageBoxPalette};
            AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&NormalWindowPara);

    return;
}

HWND *CreateControlWinWarnMessageBox(HWND* pParent,INT8U CurOsdSize)
{
    HWND* pNewControl;
   
            CREATEWINDOWPARAM Normalwindow_para = {1,{{0,0,800,480},{0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},SetWinWarnMessageBoxPalette};
            //Create Menu Window -- 1
            pNewControl = AWCreateWinControl("TWindow","WinWarnMessageBox",WS_OVERLAPPEDWINDOW,
		                      0,0,800,480,NULL, (INT32S)&Normalwindow_para,WinWarnMessageBoxMsgProc) ;
            pNewControl->win_id = 0 ;

            return pNewControl;
}

void SetWarningBoxPos(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
   
            pControl->winrect.top = pControl->parent->winrect.top + 80;
            pControl->winrect.left = pControl->parent->winrect.left + 50;
            pControl->winrect.width = 700;
            pControl->winrect.height = 340;
            pControl->draw_info_num = 6;
            RECT NormalDrawRect[6] = {
            {pControl->winrect.left + 40,pControl->winrect.top + 20,620,30},
            {pControl->winrect.left + 60,pControl->winrect.top + 26,500,28},       
            {pControl->winrect.left + 40,pControl->winrect.top + 50,620,30},
            {pControl->winrect.left + 60,pControl->winrect.top + 56,500,28},
            {pControl->winrect.left + 40,pControl->winrect.top + 80,620,30},
            {pControl->winrect.left + 60,pControl->winrect.top + 86,500,28},
            
         
            };
            for(iLoop=0; iLoop < 6; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &NormalDrawRect[iLoop], sizeof(RECT));

    return;
}

HWND *CreateControlWarningBox(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- WarningBox
    HWND *pNewControl = 0;
#ifdef ENABLE_NETWORK    
            pNewControl = AWCreateWinControl("TControl","WarningBox",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		                      80,50,700,340,pParent,0,WarningBoxMsgProc) ;
            pNewControl->win_id = 1 ;
            pNewControl->draw_info_num = 6;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO NormalDrawDatas[6] = {
                          {0,0,0,0,(INT32U)ICON_NET_SETUP_BAR,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)NET_CONNECTING_STR,DT_RESOURCE_STRING_DATA},
                          {0,0,0,0,(INT32U)ICON_NET_SETUP_BAR,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)0,DT_RESOURCE_STRING_DATA},
                          {0,0,0,0,(INT32U)ICON_NET_SETUP_BAR,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)0,DT_RESOURCE_STRING_DATA},
                          };
            memcpy(pNewControl->draw_info,NormalDrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
#endif
            return pNewControl;
}

HWND* CreateMenuWinWarnMessageBox(void)
{
    HWND *pNewControl ;
    TWINDOWS *pWin;
    HWND *pWinWarnMessageBox = CreateControlWinWarnMessageBox(NULL,CurrentOsdSize);
    SetWinWarnMessageBoxPos(pWinWarnMessageBox,CurrentOsdSize);

    pNewControl= CreateControlWarningBox(pWinWarnMessageBox,CurrentOsdSize);
    SetWarningBoxPos(pNewControl,CurrentOsdSize);

    pWin = (TWINDOWS *)pWinWarnMessageBox;
    pWin->pFocusControl = AWFindWinCtrlByName("WarningBox");
    return pWinWarnMessageBox;
}

void WinResetWinWarnMessageBoxControlsPos(HWND *pControl, INT8U CurOsdSize)
{
    switch(pControl->win_id){
        case 0://WinWarnMessageBox
            SetWinWarnMessageBoxPos(pControl,CurOsdSize) ;
            break ;
        case 1://WarningBox
            SetWarningBoxPos(pControl,CurOsdSize) ;
            break ;
    }//end of switch
}
void WinResetWinWarnMessageBoxPos(HWND *pControl, INT8U CurOsdSize)
{
    HWND *pChildControl;
    if(pControl == NULL)
        pControl = AWFindWinCtrlByName("WinWarnMessageBox");
    if(pControl == NULL) return ;

    WinResetWinWarnMessageBoxControlsPos(pControl, CurOsdSize) ;
    pChildControl = pControl->children ;
    while(pChildControl != NULL){
    	WinResetWinWarnMessageBoxPos(pChildControl, CurOsdSize) ;
    	pChildControl = pChildControl->siblings ;
	}
	return ;
}

